package com.prp.gwt.server;

import com.prp.bo.Entity;
import com.prp.gwt.client.ClientConstants;
import com.prp.gwt.client.ClientException;
import com.prp.gwt.client.user.article.ArticleService;
import com.prp.gwt.client.vo.CommentList;
import com.prp.gwt.client.vo.EntityList;
import com.prp.gwt.client.vo.SubjectCategoryList;
import com.prp.gwt.client.vo.SubjectChildCategoryList;
import com.prp.gwt.client.vo.SubjectRecommend;
import com.prp.gwt.client.vo.SubjectRecommendList;

public class ArticleServiceImpl extends GlobalServiceImpl implements
		ArticleService {

	private static final long serialVersionUID = -3864252047837065149L;

	@Override
	public EntityList search(String keyword) throws ClientException {
		validateAuth(ClientConstants.USER);
		return Entity.search(keyword);
	}

	@Override
	public com.prp.gwt.client.vo.Entity createEntity(int childCategoryId,
			String entityName) throws ClientException {
		validateAuth(ClientConstants.USER);
		return Entity.createEntity(childCategoryId, entityName);
	}

	@Override
	public SubjectCategoryList getSubjectCategoryList() throws ClientException {
		validateAuth(ClientConstants.USER);
		return Entity.getSubjectCategoryList();
	}

	@Override
	public SubjectChildCategoryList getSubjectChildCategoryList(int categoryId)
			throws ClientException {
		validateAuth(ClientConstants.USER);
		return Entity.getSubjectChildCategoryList(categoryId);
	}

	@Override
	public com.prp.gwt.client.vo.Entity getEntity(int entityId)
			throws ClientException {
		validateAuth(ClientConstants.USER);
		return Entity.getEntity(entityId);
	}

	@Override
	public SubjectRecommend getSubjectRecommend(int id) throws ClientException {
		validateAuth(ClientConstants.USER);
		return com.prp.bo.SubjectRecommend.getSubjectRecommend(id);
	}

	@Override
	public SubjectRecommendList getSubjectRecommendList(int entityId)
			throws ClientException {
		validateAuth(ClientConstants.USER);
		return com.prp.bo.SubjectRecommend.getSubjectRecommendList(entityId);
	}

	@Override
	public CommentList getCommentList(int subjectId) throws ClientException {
		validateAuth(ClientConstants.USER);
		return com.prp.bo.SubjectRecommend.getCommentList(subjectId);
	}

	@Override
	public void addComment(int subjectId, String content, int score)
			throws ClientException {
		validateAuth(ClientConstants.USER);
		com.prp.bo.SubjectRecommend.createComment(subjectId,
				(Integer) getThreadLocalRequest().getSession().getAttribute(
						ClientConstants.ATTR_USER), content, score);
	}

	@Override
	public EntityList getEntityList(int childCategoryId) throws ClientException {
		validateAuth(ClientConstants.USER);
		return Entity.getEntityList(childCategoryId);
	}

	@Override
	public int createRecommend(int entityId, String title, String content)
			throws ClientException {
		validateAuth(ClientConstants.USER);
		return com.prp.bo.SubjectRecommend.createRecommend(entityId,
				(Integer) getThreadLocalRequest().getSession().getAttribute(
						ClientConstants.ATTR_USER), title, content);
	}

	@Override
	public SubjectRecommendList getTopRecommend() throws ClientException {
		validateAuth(ClientConstants.USER);
		return com.prp.bo.SubjectRecommend.getTopRecommend();
	}

	@Override
	public EntityList getTopEntity() throws ClientException {
		validateAuth(ClientConstants.USER);
		return Entity.getTopEntity();
	}

	@Override
	public EntityList getRecentEntity() throws ClientException {
		validateAuth(ClientConstants.USER);
		return Entity.getRecentEntity();
	}

	@Override
	public void addOneClick(int subjectId) throws ClientException {
		validateAuth(ClientConstants.USER);
		com.prp.bo.SubjectRecommend.addOneClick(subjectId);
	}

	@Override
	public void deleteSubjectRecommendation(int subjectId)
			throws ClientException {
		validateAuth(ClientConstants.ADMIN);
		com.prp.bo.SubjectRecommend.deleteRecommendation(subjectId);
	}

}
